import { NoSkinCellRenderer } from "../../common/item/NoSkinCellRenderer";
import { ObjCreate } from "../../common/ObjCreate";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { GangFightsRoomData } from "../data/GangFightsRoomData";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { Language } from "../../../../../extend/language/Language";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
type int = number;
//class GangFightsEnterCellRenderer
    
    export  class GangFightsEnterCellRenderer extends NoSkinCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._btnEnter = ObjCreate.createGLoadedButton(ResFileConst.GangFightEnter, 5, 5, 105, 106, this);
            var loc1=new GTextFormat(FontUtil.EmbedNumberName, 50, 16776960);
            loc1.align = flash.text.TextFormatAlign.CENTER;
            this._tfIndex = new Object /* flash.text.TextField */();
            this._tfIndex.embedFonts = true;
            this._tfIndex.defaultTextFormat = loc1;
            ObjCreate.setObjAttri(this._tfIndex, 0, 10, 105, 50, this);
            this._tfIndex.mouseEnabled = false;
            var loc2=GlobalStyle.textFormatGreen;
            loc2.align = flash.text.TextFormatAlign.CENTER;
            this._tfScore = ObjCreate.createTextField("", 0, 57, 105, 20, this, loc2);
            this._tfScore.mouseEnabled = false;
            var loc3=GlobalStyle.textFormat6;
            loc3.align = flash.text.TextFormatAlign.CENTER;
            this._txtNum = ObjCreate.createTextField("(0/50)", 0, 77, 105, 20, this, loc3);
            this._txtNum.mouseEnabled = false;
            this._btnEnter.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnEnterClick);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            if (typeof data === "gangfightsroomdata") 
            {
                this._gangFigntsRoomData = data as GangFightsRoomData;
                this.updateView();
            }
            return;
        }

        /* internal  */onBtnEnterClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GangFightsRequestEnterWaitingRoom, this._gangFigntsRoomData.room.roomCode));
            return;
        }

        /* internal  */updateView(): void
        {
            var loc1=false;
            if ((this._gangFigntsRoomData.teamMark >= this._gangFigntsRoomData.room.minMark || this._gangFigntsRoomData.room.minMark == 0) && (this._gangFigntsRoomData.teamMark <= this._gangFigntsRoomData.room.maxMark || this._gangFigntsRoomData.room.maxMark == 0)) 
            {
                loc1 = true;
            }
            this._tfIndex.text = this._gangFigntsRoomData.index.toString();
            this._btnEnter.enabled = loc1 && this._gangFigntsRoomData.room.maxNum > this._gangFigntsRoomData.room.playerNum;
            this._txtNum.text = "(" + this._gangFigntsRoomData.room.playerNum + "/" + this._gangFigntsRoomData.room.maxNum + ")";
            this._tfScore.text = this.getScoreText(this._gangFigntsRoomData.room.minMark, this._gangFigntsRoomData.room.maxMark);
            this._btnEnter.drawNow();
            return;
        }

        /* internal  */getScoreText(arg1: int, arg2: int): string
        {
            if (arg1 == 0 && arg2 == 0) 
            {
                return Language.getString(44423);
            }
            if (arg1 == 0) 
            {
                return Language.getStringByParam(44424, arg2);
            }
            if (arg2 == 0) 
            {
                return Language.getStringByParam(44425, arg1);
            }
            return arg1 + "-" + arg2;
        }

        /* internal */ /* var */_btnEnter: GLoadedButton;

        /* internal */ /* var */_txtNum: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfScore: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfIndex: Object /* flash.text.TextField */;

        /* internal */ /* var */_gangFigntsRoomData: GangFightsRoomData;
    }
